import require from '../utils/request'

export function loginApi (data) {
  return require({
    method: 'post',
    url: 'login',
    data
  })
}
export function menusApi () {
  return require({
    method: 'get',
    url: 'menus'
    // headers: { Authorization: localStorage.getItem('token') }
  })
}
// 获取表格数据
export function usersApi (pagenum, pagesize, query) {
  return require({
    method: 'get',
    url: 'users',
    params: {
      query,
      pagenum,
      pagesize
    }
  })
}
// 添加用户
export function usersAddApi (data) {
  return require({
    method: 'post',
    url: 'users',
    data
  })
}
// 删除用户
export function usersremoveApi (id) {
  return require({
    method: 'delete',
    url: `users/${id}`
  })
}
// 修改用户
export function usersChangeApi (obj) {
  return require({
    method: 'put',
    url: `users/${obj.id}`,
    data: {
      email: obj.email,
      mobile: obj.mobile
    }
  })
}
// 修改用户状态
export function usersStetaApi (state, id) {
  return require({
    method: 'put',
    url: `users/${id}/state/${state}`
  })
}
// 获取商品分类
export function goodsParamsApi (params) {
  return require({
    method: 'get',
    url: 'categories',
    params
  })
}
// 分类参数管理
export function goodsParamsLayerApi (id, sel) {
  return require({
    method: 'get',
    url: `categories/${id}/attributes`,
    params: {
      sel
    }
  })
}
/* 获取商品分类数据 */
export function goodsCateApi (params) {
  return require({
    method: 'get',
    url: 'categories',
    params: params
  })
}
// 添加动态参数或者静态属性
export function goodsAddApi (obj, editableTabsValue, dynamicTags) {
  return require({
    method: 'put',
    url: `categories/${obj.cat_id}/attributes/${obj.attr_id}`,
    data: {
      attr_name: obj.attr_name,
      attr_sel: editableTabsValue,
      attr_vals: dynamicTags
    }
  })
}
// 图片上传
export function addUploadImgApi (file) {
  return require({
    method: 'post',
    url: 'upload',
    data: {
      file
    }
  })
}
